package com.jsgt.greekfire.ui.main.snapup.adapter

import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.SnapUpBean

/**
 * author fhx
 * create time 2020/4/30 14:46
 **/
class SnapUpAdapter : BaseAdapter<SnapUpBean>() {
    var currentGuid: String? = null

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var ratio_tv: TextView? = null
        var conDecimal_tv: TextView? = null
        var line: View? = null

        init {
            ratio_tv = itemView.findViewById(R.id.ratio_tv)
            conDecimal_tv = itemView.findViewById(R.id.conDecimal_tv)
            line = itemView.findViewById(R.id.line)
        }

        fun bindData(bean: SnapUpBean) {
            ratio_tv?.text = bean.ratio + "%"
            conDecimal_tv?.text = bean.conDecimal.toString() + "U"
//            if (DateFormatUtil.dateEquals(bean.startTime!!)) {
            if (TextUtils.equals(currentGuid, bean.guid)) {
                ratio_tv?.setTextColor(itemView.resources.getColor(R.color.white))
                conDecimal_tv?.setTextColor(itemView.resources.getColor(R.color.white))
                line?.visibility = View.VISIBLE
            } else {
                ratio_tv?.setTextColor(itemView.resources.getColor(R.color.gray_4C5E6A))
                conDecimal_tv?.setTextColor(itemView.resources.getColor(R.color.gray_4C5E6A))
                line?.visibility = View.GONE
            }
//            }
        }
    }

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_snap_up, parent, false)
        return VH(view)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }
}